<template>
  <view class="login">
	  
	
    <view class="login-tel">
      <view class="tel-main">
		  <view class="logo">
		  	<image src="../../static/logoall3.png" alt="">
		  </view>
		
	
		  	<view class="uni-px-5 uni-pb-5">
		 
		  		<uni-data-checkbox class="sex" v-model="radio1" :localdata="sex"></uni-data-checkbox>
		  	</view>
		  </uni-section>
		  
		  <button class="tel" @click="gonextcode">保存</button>

      </view>


    </view>
  </view>
    </view>
  
</template>

<script>
	import {mapMutations} from 'vuex';
	import $http from '@/common/api/request.js'//引入request组件


export default {
  data() {
    return {
		radio1: 0,
				
		checkbox1: [0],
				
		sex: [{
			text: '男',
			value: 1
		}, {
			text: '女',
			value: 0
		},],
    selectedGender: '',
      userName: '',
	  userId:'',
	  phone:'',
	  user:[],
	users:[],
      showTip: false,

      rules: {
        userName: {
          rule:null,
          msg: "请输入正确的11位手机号"
        },
       
      },
    }
  },
  onLoad() {},
  onReady() {},
  mounted() {

 
  	//全局变量用户ID
  //	this.userId = uni.getStorageSync('userId');
  		this.user = uni.getStorageSync('user');
  		//this.userName = uni.getStorageSync('user.name');
  		console.log('5551',this.user.id)
  	//this.address(,;
  },
  methods: {
	  
	  goToBack() {
	  	uni.navigateTo({
	  		url: '/pages/set/set'
	  	})
	  },
  saveSelection() {
    // 在这里保存选择的值
    var data=this.radio1
    console.log("保存选择的值:", this.radio1);
    console.log("保存选择的值:", data);
  },
 
gonextcode() {
      // 在这里保存选择的值
				  var data=this.radio1
			      console.log("保存选择的值:", this.radio1);
			      console.log("保存选择的值1:", data);
  var userId = this.user.id;
  console.log('669', this.user.id)
  var url = 'http://43.136.172.73/api/v1/user/upgrade_sex';


  url += '?sex=' + encodeURIComponent(data) + '&userId=' + encodeURIComponent(userId);

  uni.request({
    url: url,
    method: 'PUT',
    header: {
      'Content-Type': 'application/json',
      "Content-Type": "application/x-www-form-urlencoded",
      'Authorization': 'sfsdf',
    },
    success: (res)=> {
      // 请求成功处理
      console.log('请求成功！',res);
	uni.request({
	  url: 'http://43.136.172.73/api/v1/user/load',
	  method: 'GET',
	  data: { 
	  	phone: this.user.phone, //给后端给的phone
	  },
	  header: {
	    'Content-Type': 'application/json',
	    'Content-Type': 'application/x-www-form-urlencoded',
	    'Authorization': 'sfsdf'
	  },
	  success: (res) => {
		  	console.log('5555:', this.user.phone)
	console.log('99966:', res.data)

   uni.showToast({
		          title: '修改成功',
		          icon: 'none',
		          duration: 2000
		        });
	setTimeout(() => {
				  uni.navigateTo({
				    url: '../set/set?username=' + this.users.name
				  });
				}, 2000);
	
	  },
	  fail: (err) => {
	    console.error('Error:', err)
	  }
	})
    },
    fail: (err)=> {
      // 请求失败处理
      console.log('请求失败！', err);
    }
  });
  
/////////////////////////////////////////////////////////////////////////
  
///加载

		
    }
  }
}
</script>

<style>
	.content-title {
		background-color: #fff;
		color: #000;
		font-weight: bold;
		height: 100rpx;
		position: relative;
		font-size: 16px;
	
		.title-left {
			position: absolute;
			left: 30rpx;
			top: 50%;
			transform: translate(-50%, -50%);
		}
	
		.title-right {
			text-align: center;
			line-height: 100rpx;
		}
	}
	
.login-tel {
	  display: flex;
	  justify-content: center;
  padding: 30rpx;
  width: 100vw;
  height: 100vh;
}

.tel-main {

  padding: 0rpx 20rpx;
  padding-top: 0rpx;
}
.logo{
	padding-top: 70rpx;
	padding-bottom: 80rpx;
	display: flex;
	justify-content: center;
	
}
.tel {
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  color: #FFFF;
  background-color: #49BDFB;
  border-radius: 40rpx;
}

.login-form{

}

.login-user{
position: relative;
  display: flex;
 align-items: center;
  height: 100rpx;
  line-height: 100rpx;
  text-align: left;
  color:black;
  background-color: #f7f7f7;
  border-radius: 40rpx;
  padding: 20rpx 0;
  margin: 40rpx 0rpx;
  border-bottom: 2rpx solid #f7f7f7;
}

.user-text{
  margin-left: 20rpx;
  padding-right: 10rpx;
  font-size: 31rpx;
  text-align: center;
  align-items: center;
  color: black;
  font-weight: 400;
}

.show-pwd {
  position: absolute;
  right: 50rpx;
  color: #49BDFB;
  padding-top: 10rpx;
  padding-bottom: 10rpx;
  cursor: pointer;

}

.no-border {
outline: none;
  border:none ;
  background-color: #f7f7f7;
  display: flex;
  align-items: center;
  height: 50rpx;
  line-height: 50rpx;
  font-size: 28rpx; 
}

.btn {
  margin-left: -20rpx;
  margin-right: -20rpx;
  padding: 50rpx;
}
.tip{
	color: red;
}
.radio-group {
  display: flex;
  flex-direction: row;
  margin: 20rpx;
}

.radio-group .radio {
  --color: #1194f6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15rpx;
  height: 15rpx;
  border-radius: 50%;
  padding: 40rpx;

  cursor: pointer;
}

.radio-group .radio input[type="radio"] {
  opacity: 0;
  position: absolute;
}

.radio-group .radio label {
  font-size: 14px;
  color: #333;
  cursor: pointer;
}
	.text {
		font-size: 12px;
		color: #666;
		margin-top: 5px;
	}

	.uni-px-5 {
		padding-left: 10px;
		padding-right: 10px;
	}

	.uni-pb-5 {
		padding-bottom: 10px;
	}

.radio-group .radio input[type="radio"]:checked + label {
  font-weight: bold;
  color: var(--color);
}
</style>

